package Threads.ReentrantLock.fixed_sequence;

import javafx.beans.binding.ObjectExpression;

public class wait_notify {

    static private Object o=new Object();

    static private boolean flag=false;

    public static void main(String[] args) {
            Thread t1=new Thread(()->{
                synchronized (o) {
                    while (!flag) {
                        try {
                            o.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    System.out.println("t1 running");
                }
            },"t1");

            Thread t2=new Thread(()->{
                System.out.println("t2 running");
                synchronized (o){
                    flag=true;
                    o.notify();
                }
            },"t2");

            t1.start();
            t2.start();
    }
}
